package com.centaline.androidsalesblog.activities.newest;

import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;

import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.base.BaseActivity;
import com.centaline.androidsalesblog.constants.ExtraConstant;
import com.centaline.androidsalesblog.model.businissobject.BaseNewPropBo;
import com.centaline.androidsalesblog.model.businissobject.NewPropExtInfoBo;
import com.centaline.androidsalesblog.utils.DateUtil;

import java.util.Locale;

/**
 * 新房 更多楼盘资料
 */
public class NewEstInfoActivity extends BaseActivity {

    private AppCompatTextView atv_developer, atv_pre_sale_permit, atv_status, atv_average_price, atv_op_date, atv_live_date, atv_district,
            atv_address, atv_sales_office, atv_est_type, atv_building_types, atv_fitment, atv_arch_style, atv_mgt_company, atv_mgt_price,
            atv_lift_desc, atv_prop_year, atv_room_ratio, atv_green_ratio, atv_floor_ratio, atv_plan_unit, atv_park;

    private LinearLayout ll_developer, ll_pre_sale_permit, ll_status, ll_average_price, ll_op_date, ll_live_date, ll_district,
            ll_address, ll_sales_office, ll_est_type, ll_building_types, ll_fitment, ll_arch_style, ll_mgt_company, ll_mgt_price,
            ll_lift_desc, ll_prop_year, ll_room_ratio, ll_green_ratio, ll_floor_ratio, ll_plan_unit, ll_park;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_new_est_info;
    }

    @Override
    protected void findViews() {
        atv_developer = (AppCompatTextView) findViewById(R.id.atv_developer);
        atv_pre_sale_permit = (AppCompatTextView) findViewById(R.id.atv_pre_sale_permit);
        atv_status = (AppCompatTextView) findViewById(R.id.atv_status);
        atv_average_price = (AppCompatTextView) findViewById(R.id.atv_average_price);
        atv_op_date = (AppCompatTextView) findViewById(R.id.atv_op_date);
        atv_live_date = (AppCompatTextView) findViewById(R.id.atv_live_date);
        atv_district = (AppCompatTextView) findViewById(R.id.atv_district);
        atv_address = (AppCompatTextView) findViewById(R.id.atv_address);
        atv_sales_office = (AppCompatTextView) findViewById(R.id.atv_sales_office);
        atv_est_type = (AppCompatTextView) findViewById(R.id.atv_est_type);
        atv_building_types = (AppCompatTextView) findViewById(R.id.atv_building_types);
        atv_fitment = (AppCompatTextView) findViewById(R.id.atv_fitment);
        atv_arch_style = (AppCompatTextView) findViewById(R.id.atv_arch_style);
        atv_mgt_company = (AppCompatTextView) findViewById(R.id.atv_mgt_company);
        atv_mgt_price = (AppCompatTextView) findViewById(R.id.atv_mgt_price);
        atv_lift_desc = (AppCompatTextView) findViewById(R.id.atv_lift_desc);
        atv_prop_year = (AppCompatTextView) findViewById(R.id.atv_prop_year);
        atv_room_ratio = (AppCompatTextView) findViewById(R.id.atv_room_ratio);
        atv_green_ratio = (AppCompatTextView) findViewById(R.id.atv_green_ratio);
        atv_floor_ratio = (AppCompatTextView) findViewById(R.id.atv_floor_ratio);
        atv_plan_unit = (AppCompatTextView) findViewById(R.id.atv_plan_unit);
        atv_park = (AppCompatTextView) findViewById(R.id.atv_park);

        ll_developer = (LinearLayout) findViewById(R.id.ll_developer);
        ll_pre_sale_permit = (LinearLayout) findViewById(R.id.ll_pre_sale_permit);
        ll_status = (LinearLayout) findViewById(R.id.ll_status);
        ll_average_price = (LinearLayout) findViewById(R.id.ll_average_price);
        ll_op_date = (LinearLayout) findViewById(R.id.ll_op_date);
        ll_live_date = (LinearLayout) findViewById(R.id.ll_live_date);
        ll_district = (LinearLayout) findViewById(R.id.ll_district);
        ll_address = (LinearLayout) findViewById(R.id.ll_address);
        ll_sales_office = (LinearLayout) findViewById(R.id.ll_sales_office);
        ll_est_type = (LinearLayout) findViewById(R.id.ll_est_type);
        ll_building_types = (LinearLayout) findViewById(R.id.ll_building_types);
        ll_fitment = (LinearLayout) findViewById(R.id.ll_fitment);
        ll_arch_style = (LinearLayout) findViewById(R.id.ll_arch_style);
        ll_mgt_company = (LinearLayout) findViewById(R.id.ll_mgt_company);
        ll_mgt_price = (LinearLayout) findViewById(R.id.ll_mgt_price);
        ll_lift_desc = (LinearLayout) findViewById(R.id.ll_lift_desc);
        ll_prop_year = (LinearLayout) findViewById(R.id.ll_prop_year);
        ll_room_ratio = (LinearLayout) findViewById(R.id.ll_room_ratio);
        ll_green_ratio = (LinearLayout) findViewById(R.id.ll_green_ratio);
        ll_floor_ratio = (LinearLayout) findViewById(R.id.ll_floor_ratio);
        ll_plan_unit = (LinearLayout) findViewById(R.id.ll_plan_unit);
        ll_park = (LinearLayout) findViewById(R.id.ll_park);

    }

    @Override
    protected void initViews() {

        NewPropExtInfoBo newPropExtInfoBo = getIntent().getParcelableExtra(ExtraConstant.NewEstInfo);
        BaseNewPropBo baseNewPropBo = newPropExtInfoBo.getBaseNewPropBo();
        setUniversalToolbar(newPropExtInfoBo.getAdName());

        setText(ll_developer, atv_developer, baseNewPropBo.getDeveloper());
        setText(ll_pre_sale_permit, atv_pre_sale_permit, baseNewPropBo.getPreSalePermit());
        setText(ll_status, atv_status, ("认购".equals(newPropExtInfoBo.getBaseNewPropBo().getStatus()) || "持销".equals(newPropExtInfoBo
                .getBaseNewPropBo().getStatus()) || "尾盘".equals(newPropExtInfoBo.getBaseNewPropBo().getStatus())) ? "在售" : "待售");
        setText(ll_average_price, atv_average_price, newPropExtInfoBo.getAveragePrice() == 0 ? "" :
                String.format(Locale.CHINA, "%.0f元/平", newPropExtInfoBo.getAveragePrice()));
        setText(ll_op_date, atv_op_date, TextUtils.isEmpty(newPropExtInfoBo.getOpDate()) ? "" :
                DateUtil.format(newPropExtInfoBo.getOpDate(), DateUtil.FORMAT2, DateUtil.FORMAT7));
        setText(ll_live_date, atv_live_date, newPropExtInfoBo.getLiveDate());
        setText(ll_district, atv_district, String.format(Locale.CHINA, "%s-%s",
                baseNewPropBo.getNewEstDistrictBo() == null ? "暂无" : baseNewPropBo.getNewEstDistrictBo().getGScopeCnName(),
                baseNewPropBo.getNewEstGScopeBo() == null ? "暂无" : baseNewPropBo.getNewEstGScopeBo().getGScopeCnName()));
        setText(ll_address, atv_address, baseNewPropBo.getAddress());
        setText(ll_sales_office, atv_sales_office, baseNewPropBo.getSalesOffice());
        setText(ll_est_type, atv_est_type, newPropExtInfoBo.getEstType());
        setText(ll_building_types, atv_building_types, newPropExtInfoBo.getBuildingTypes());
        setText(ll_fitment, atv_fitment, baseNewPropBo.getFitment());
        setText(ll_arch_style, atv_arch_style, newPropExtInfoBo.getArchitecturalStyle());
        setText(ll_mgt_company, atv_mgt_company, baseNewPropBo.getMgtCompany());
        setText(ll_mgt_price, atv_mgt_price, newPropExtInfoBo.getMgtPrice() == 0 ? "" :
                String.format(Locale.CHINA, "%.2f元/平/月", newPropExtInfoBo.getMgtPrice()));
        setText(ll_lift_desc, atv_lift_desc, newPropExtInfoBo.getLiftDescription());
        setText(ll_prop_year, atv_prop_year, newPropExtInfoBo.getPropertyRight() == 0 ? "" :
                String.format(Locale.CHINA, "%d年", newPropExtInfoBo.getPropertyRight()));
        setText(ll_room_ratio, atv_room_ratio, newPropExtInfoBo.getRoomRatio() == 0 ? "" :
                String.format(Locale.CHINA, "%.0f%%", newPropExtInfoBo.getRoomRatio()));
        setText(ll_green_ratio, atv_green_ratio, baseNewPropBo.getGreenRatio() == 0 ? "" :
                String.format(Locale.CHINA, "%.0f%%", baseNewPropBo.getGreenRatio()));
        setText(ll_floor_ratio, atv_floor_ratio, baseNewPropBo.getFloorRatio() == 0 ? "" :
                String.format(Locale.CHINA, "%.2f", baseNewPropBo.getFloorRatio()));
        setText(ll_plan_unit, atv_plan_unit, baseNewPropBo.getPlanUnit() == 0 ? "" :
                String.format(Locale.CHINA, "%d户", baseNewPropBo.getPlanUnit()));
        setText(ll_park, atv_park, baseNewPropBo.getPark());

    }

    private void setText(LinearLayout ll, AppCompatTextView atv, String data) {
        if (TextUtils.isEmpty(data)) {
            ll.setVisibility(View.GONE);
            return;
        }
        atv.setText(data);
    }
}
